<template>
  <div class="theme-switcher">
    <a-dropdown placement="bottomRight" trigger="click">
      <a-button type="text" class="theme-switch-btn">
        <template #icon>
          <BgColorsOutlined />
        </template>
        <span class="theme-label">{{ currentThemeConfig.label }}</span>
        <DownOutlined class="dropdown-arrow" />
      </a-button>
      
      <template #overlay>
        <a-menu class="theme-menu" @click="handleThemeChange">
          <a-menu-item 
            v-for="theme in availableThemes" 
            :key="theme.name"
            :class="{ 'theme-item-active': currentTheme === theme.name }"
          >
            <div class="theme-item">
              <div class="theme-preview" :style="{ backgroundColor: theme.colors.primary }"></div>
              <span class="theme-name">{{ theme.label }}</span>
              <CheckOutlined v-if="currentTheme === theme.name" class="theme-check" />
            </div>
          </a-menu-item>
        </a-menu>
      </template>
    </a-dropdown>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { 
  BgColorsOutlined, 
  DownOutlined, 
  CheckOutlined 
} from '@ant-design/icons-vue'
import { useThemeStore } from '@/stores/useThemeStore'

const themeStore = useThemeStore()

// 当前主题
const currentTheme = computed(() => themeStore.currentTheme)

// 当前主题配置
const currentThemeConfig = computed(() => themeStore.themeConfig)

// 可用主题列表
const availableThemes = computed(() => themeStore.availableThemes)

// 处理主题切换
const handleThemeChange = ({ key }: { key: string }) => {
  themeStore.switchTheme(key)
}
</script>

<style scoped>
.theme-switcher {
  display: inline-block;
}

.theme-switch-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  border-radius: 6px;
  transition: all 0.3s ease;
  color: var(--theme-text);
  background: var(--theme-surface);
  border: 1px solid var(--theme-border);
}

.theme-switch-btn:hover {
  background: var(--theme-background);
  border-color: var(--theme-primary);
  color: var(--theme-primary);
}

.theme-label {
  font-size: 14px;
  font-weight: 500;
}

.dropdown-arrow {
  font-size: 12px;
  transition: transform 0.3s ease;
}

.theme-switch-btn:hover .dropdown-arrow {
  transform: rotate(180deg);
}

.theme-menu {
  min-width: 200px;
  padding: 8px 0;
  background: var(--theme-surface);
  border: 1px solid var(--theme-border);
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--theme-shadow);
}

.theme-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  transition: all 0.3s ease;
}

.theme-item:hover {
  background: var(--theme-background);
}

.theme-preview {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 2px solid var(--theme-border);
}

.theme-name {
  flex: 1;
  font-size: 14px;
  color: var(--theme-text);
}

.theme-check {
  color: var(--theme-primary);
  font-size: 14px;
}

.theme-item-active {
  background: var(--theme-background);
}

.theme-item-active .theme-name {
  color: var(--theme-primary);
  font-weight: 500;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .theme-label {
    display: none;
  }
  
  .theme-switch-btn {
    padding: 0 8px;
  }
}
</style> 